<template>
  <div class="app-container ">
    <div class="container-flex book">
      <div class="block" v-for="(item,index) in list" :key="index" @click="goToInfo(item)">
        <div class="book-item">
          <span class="book-cover" :style="{backgroundImage:'url('+item.cover+')'}"></span>
          <span class="book-name" v-html="item.name">生而平凡</span>
        </div>
      </div>
    </div>
    <div class="pagination">
      <el-pagination @current-change="handleCurrentChange" :current-page.sync="currentPage" :page-size="pageSize" layout="total, prev, pager, next, jumper" :total="total">
      </el-pagination>
    </div>
  </div>
</template>

<script>
import { myCollect } from "@/api/index";
export default {
  data() {
    return {
      currentPage: 1,
      list: [],
      total:0,
      pageSize:16
    };
  },
  components: {},
  created() {
    this.init();
  },
  watch: {
    $route() {
      this.currentPage = Number(this.$route.query.currentPage) || 1;
      this.init(this.currentPage);
    }
  },
  methods: {
     goToInfo(item) {
      this.$router.push("/book/info?bookId=" + item.fileId+"&bookName="+item.name);
    },
    init(pageNo) {
      myCollect(1, pageNo, this.pageSize).then(res => {
        console.log(res.data.date.list);
        this.total = res.data.date.total
        this.list = res.data.date.list;
      });
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      this.$router.push(this.$route.path + "?currentPage=" + this.currentPage);
    }
  }
};
</script>
<style lang="less" scoped>
.book {
  flex-wrap: wrap;
  justify-content: flex-start;
  .block {
    margin-left: 98px;
    cursor: pointer;
    .book-item {
      width: 140px;
      .book-cover {
        background: url("/static/images/base/book.png");
        background-size: cover;
        border-radius: 10px;
        width: 140px;
        height: 188px;
        display: block;
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
      }
      .book-name {
        margin-top: 12px;
        margin-bottom: 28px;
        display: block;
        font-size: 18px;
        text-align: center;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 1;
        overflow: hidden;
      }
    }
  }
  .block:nth-child(4n + 1) {
    margin-left: 0px;
  }
}
</style>

